<?php

namespace Wilead\IArtistBundle\Filter;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UserAlbumsFilter
 *
 * @author jack
 */
class UserAlbumsFilter extends AbstractType {

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder->add('systemNum', 'filter_text', array(
            'label' => 'I艺人号',
            'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                if($values['value']){
                    $queryBuilder = $filterQuery->getQueryBuilder();
                    $queryBuilder->andWhere('u.systemNum = :num')->setParameter('num', $values['value']);
                }
            },
        ));
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'csrf_protection' => FALSE,
            'validation_groups' => array('filtering')
        ));
    }

    /**
     * @return string
     */
    public function getName() {
        return 'wilead_iartistbundle_useralbums_filter';
    }

}
